package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Date;


@Component  //将对象交给spring容器管理 它不属于任意一层
public class MyMetaObjectHandler implements MetaObjectHandler {

   //入库时操作操作
    /*
    * arg1自动填充的属性名 arg2：自动填充的值 arg3：metaObject
    * */
    @Override
    public void insertFill(MetaObject metaObject) {
        Date data=new Date();
       this.setFieldValByName("created",data,metaObject );
        this.setFieldValByName("updated",data,metaObject );


    }

    //更新操作是调用
    @Override
    public void updateFill(MetaObject metaObject) {

        this.setFieldValByName("updated",new Date(),metaObject );
    }
}
